package com.chang.multithread;

import lombok.extern.slf4j.Slf4j;



//线程的六种状态
@Slf4j
public class State {
    public static void main(String[] args) {
        Thread t1=new Thread("t1"){
            @Override
            public void run() {
                log.debug("新建状态");
            }
        };


        Thread t2=new Thread("t2"){
            @Override
            public void run() {
               while (true){   //运行状态 runnable

               }
            }
        };
        t2.start();

        Thread t3=new Thread(){
            @Override
            public void run() {
                log.debug("运行完之后转化为终止状态");
            }
        };
        t3.start();

        Thread t4=new Thread(){
            @Override
            public void run() {
                synchronized (State.class) {
                    try {
                        Thread.sleep(50000);  //timed_waiting  有时限的等待状态
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t4.start();

        Thread t5=new Thread(){
            @Override
            public void run() {
                try {
                    t2.join();//waiting t2执行完之后才会执行t5
                    // 因为t2处于一直运行状态，不会结束，则t5就处于阻塞状态
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        t5.start();

        Thread t6=new Thread(){
            @Override
            public void run() {
                synchronized (State.class) {
                    try {
                        Thread.sleep(50000); //同步锁只能执行一个，t6就处于block状态
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t6.start();


        try {
           Thread.sleep(500);
          } catch (InterruptedException e) {
          e.printStackTrace(); }

       log.debug("t1 state:{}",t1.getState());
       log.debug("t2 state:{}",t2.getState());
       log.debug("t3 state:{}",t3.getState());
       log.debug("t4 state:{}",t4.getState());
       log.debug("t5 state:{}",t5.getState());
       log.debug("t6 state:{}",t6.getState());


    }
}
